package com.anjie.powerproject.map.impl;

import com.anjie.powerproject.entity.Model;
import com.anjie.powerproject.map.ModelMap;
import com.anjie.powerproject.pojo.dto.ModelVersion;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class ModelMapImpl implements ModelMap {

    @Override
    public ModelVersion toDTO(Model model) {
        if ( model == null ) {
            return null;
        }

        ModelVersion modelVersion = new ModelVersion();

        if ( model.getId() != null ) {
            modelVersion.setModelVersion( model.getId().longValue() );
        }
        modelVersion.setUsed( intToBool( model.getIsUsed() ) );
        modelVersion.setModelName( model.getModelName() );
        modelVersion.setModelInfo( model.getModelInfo() );
        return modelVersion;
    }

    @Override
    public List<ModelVersion> toDTO(List<Model> models) {
        if ( models == null ) {
            return null;
        }

        List<ModelVersion> list = new ArrayList<ModelVersion>( models.size() );
        for ( Model model : models ) {
            list.add( toDTO( model ) );
        }

        return list;
    }
}
